<template>
	<view class="">
		<u-sticky>
			<view class="bg_main p-2">
				<scroll-view scroll-x="true" show-scrollbar="false" class="scroll_cont">
					<view class="flex">
						<view
							class="tab_item c_main bg-white font_24 font-weight-bolder rounded_15 text-center"
							v-for="(tab, tabidx) of tabs"
							:key="tabidx"
							:class="{ tab_active: tabcur == tabidx }"
							@click="tabChange(tabidx)"
						>
							{{ tab }}
						</view>
					</view>
				</scroll-view>
			</view>
		</u-sticky>
		<view class="">
			<!-- 企业信息 -->
			<!-- <view v-if="tabcur == 0" class="msgcont bg-white h_100"><message></message></view> -->
			<!-- 产品管理 -->
			<view v-if="tabcur == 0" class="p_bottom"><product ref="productList" @productSort="productSort" @delChange="delChange" @delAfter="delAfter"></product></view>
			<!-- 询价管理 -->
			<!-- <view v-else-if="tabcur == 1"><enquiry :offset-top="'93rpx'" :ismy="true"></enquiry></view> -->
			<!-- 荣誉管理 -->
			<view v-else-if="tabcur == 1" class="p_bottom"><honor ref="honor" :ismy="true" @delChange="delChange" @delAfter="delAfter"></honor></view>
			<!-- 项目管理 -->
			<view v-else-if="tabcur == 2" class="p_bottom"><case-list ref="case" :ismy="true" @delChange="delChange" @delAfter="delAfter"></case-list></view>
			<!-- 资讯管理 -->
			<view v-else-if="tabcur == 3" class="p_bottom"><info-list ref="info" :ismy="true" @delChange="delChange" @delAfter="delAfter"></info-list></view>
			<!-- 资料管理 -->
			<view v-else class=""><data-upload ref="dataUpload" @delChange="delChange" @delAfter="delAfter"></data-upload></view>
		</view>
		<!-- <button v-if="tabcur == 0" class="fix_bottom bg_main text-center h4 text-white" @click="newPut">保存</button> -->
		<!-- v-if="tabcur != 0 && tabcur != 2" -->
		<view class="fix_bottom flex align-center h4 text-white">
			<view class="put bg_main text-center" @click="newPut">{{ tabcur == 4 ? '新上传' : '新发布+' }}</view>
			<view class="del text-center" :class="{ c_main: delNum >= 1 }" @click="deleteChange">
				删除
				<text v-if="delNum >= 1">({{ delNum }})</text>
			</view>
		</view>
		<!-- 产品选择 -->
		<u-overlay :show="productShow" @click="productShow = false" zIndex="995">
			<view class="product_select">
				<view class="rect h4 px-4 text-center" @tap.stop>
					<view class="py-2" @click="goPages('/subPages/my/company_main/publish/product_img_put?mid=' + productMid)">图文产品</view>
					<view class="py-2" @click="category">参数产品</view>
				</view>
				<!-- 参数型产品选择分类 -->
				<view class="rect h4 px-4 text-center" @tap.stop v-if="categoryShow">
					<view class="py-2" v-for="item of productCate" :key="item.id" @click="goPages('/subPages/my/company_main/product/launch?mid=' + item.id)">
						{{ item.title }}
					</view>
				</view>
			</view>
		</u-overlay>
	</view>
</template>

<script>
import { productCategory } from '@/api/home/nav/product_data.js';
import message from './publish/message.vue';
import product from './product/index.vue';
import enquiry from '@/subPages/my/list/enquiry/index.vue';
import honor from '@/subPages/company_home/honor.vue';
import caseList from '@/subPages/company_home/case.vue';
import infoList from '@/subPages/company_home/info.vue';
import dataUpload from './publish/data_upload.vue';
export default {
	components: { message, product, enquiry, honor, caseList, infoList, dataUpload },
	options: { styleIsolation: 'shared' },
	data() {
		return {
			// '企业信息',
			tabs: ['产品管理', '荣誉管理', '项目管理', '资讯管理', '资料管理'], //'询价管理',
			tabcur: 0,
			productShow: false,
			productMid: '', //产品分类id
			delNum: 0,
			productCate: [], //产品分类
			categoryShow: false
		};
	},
	onReachBottom() {
		if (this.tabcur == 0) {
			uni.$emit('onReachBottom1');
		}
	},
	onUnload() {
		uni.navigateTo({ url: '/pages/my/index' });
	},
	onBackPress(options) {
		uni.navigateTo({ url: '/pages/my/index' });
	},
	onShow() {
		this.productShow = false;
		// this.tabChange(this.tabcur);
	},
	onLoad(option) {
		if (option.tab) {
			this.tabChange(option.tab);
		}
	},

	methods: {
		tabChange(idx) {
			this.tabcur = idx;
			this.delNum = 0;
		},
		// 新发布
		newPut() {
			if (this.tabcur == 0) {
				this.productShow = true;
				this.categoryShow = false;
			} else if (this.tabcur == 1) {
				uni.navigateTo({
					url: '/subPages/my/company_main/publish/honor_put'
				});
			} else if (this.tabcur == 2) {
				uni.navigateTo({
					url: '/subPages/my/company_main/publish/case_put'
				});
			} else if (this.tabcur == 3) {
				uni.navigateTo({
					url: '/subPages/my/company_main/publish/info_put'
				});
			} else if (this.tabcur == 4) {
				// 上传资料
				this.$refs.dataUpload.fileUpload();
			}
		},
		// 获取产品分类id
		productSort(val) {
			this.productMid = val;
		},
		// 删除
		deleteChange() {
			if (this.delNum == 0) {
				uni.$u.toast('请选择要删除的内容');
			} else {
				if (this.tabcur == 0) {
					this.$refs.productList.checkDel();
				} else if (this.tabcur == 1) {
					this.$refs.honor.checkDel();
				} else if (this.tabcur == 2) {
					this.$refs.case.checkDel();
				} else if (this.tabcur == 3) {
					this.$refs.info.checkDel();
				} else if (this.tabcur == 4) {
					this.$refs.dataUpload.checkDel();
				}
			}
		},
		// 选择删除的数量
		delChange(num) {
			// console.log('==', num);
			this.delNum = num;
		},
		delAfter() {
			this.delNum = 0;
		},
		// 参数产品选择分类
		category() {
			productCategory()
				.then(res => {
					if (res.code == 0) {
						this.productCate = res.data;
						this.categoryShow = true;
					} else {
						uni.$u.toast(res.msg);
					}
				})
				.catch(err => {
					console.log('获取产品分类失败', err);
				});
		}
	}
};
</script>

<style lang="scss" scoped>
.scroll_cont {
	white-space: nowrap;
	width: 100%;
}
.tab_item {
	padding: 0rpx 17rpx;
	// width: 150rpx;
	// width: 110rpx;
	height: 56rpx;
	line-height: 56rpx;
	margin-right: 16rpx;
}
.tab_active {
	background: linear-gradient(0deg, #d73342, #e5525f);
	box-shadow: 0px 0px 4rpx 0px #ffffff;
	border-radius: 14rpx;
	color: $color2;
}
.fix_bottom {
	width: 100%;
	height: 98rpx;
	line-height: 98rpx;
	position: fixed;
	bottom: 0;
	left: 0;
	z-index: 999;
	.put {
		width: 70%;
	}
	.del {
		width: 30%;
		background-color: #d3d3d3;
	}
}
.p_bottom {
	padding-bottom: 100rpx;
}
.product_select {
	display: flex;
	align-items: center;
	justify-content: center;
	height: 100%;
	.rect {
		width: 420rpx;
		// height: 190rpx;
		background: $color2;
		border-radius: 14rpx 14rpx 0px 0px;
		position: absolute;
		bottom: 100rpx;
		right: 30%;
	}
	.rect view:last-child {
		border-top: 1px solid #919191;
	}
}
::v-deep .u-upload__wrap {
	position: absolute !important;
}
::v-deep .msgcont .u-upload__button,
::v-deep .u-upload__wrap__preview__other {
	min-width: 704rpx;
	width: 100% !important;
	height: 395rpx !important;
	border: 1px solid #dedede;
}
</style>
